<?php

require_once 'smarty_lib/Smarty.class.php';
require_once 'lib/DBClass.php';
require_once 'lib/Member.php';
require_once 'lib/Game.php';

$smarty = new Smarty();
$acc = new Member();
$game = new Game();

$smarty->template_dir = 'template/';
$smarty->compile_dir = 'template_c/';

if(isset($_POST['submit'])){
	
	if($_POST['usr']=='' or $_POST['pwd']=='')
		$smarty->assign('error','User dan Password harus diisikan');
	else{
		
		$acc->set_user($_POST['usr']);
		$acc->set_password($_POST['pwd']);
		
		if($acc->do_login()){
			header('location: dashboard.php');
		}else{
			$smarty->assign('error','User dan Password tidak sesuai,<br />silahkan periksa kembali');
		}			
	}		
	
}else if(isset($_GET['a']) && $_GET['a']=='logout'){
	$acc->do_logout();
	header('location: index.php');
	$smarty->assign('error','Anda telah berhasil Logout dari Admin');
	$smarty->assign('page','game.html');
	$smarty->display('dashboard.html');

}else if($acc->validate_cookie()){
	header('location: dashboard.php');
}else{

	$smarty->assign('page','game.html');
	$smarty->assign('title','Halaman Depan');

	$data = $game->get_all_game();
	$smarty->assign('game', $data);

	$smarty->display('dashboard.html');

	if (@$_GET['action'] == 'detail') {
		$idgame = $_GET['idgame'];
		$game->game_detail($idgame);
		$smarty->assign('page','product.html');
		header('loaction: game_det.php');
	}
}
?>